/*
 * @Author: 李超越 1509572300@qq.com
 * @Date: 2024-07-30 11:50:57
 * @LastEditors: 李超越 1509572300@qq.com
 * @LastEditTime: 2024-07-30 13:11:10
 * @FilePath: /my_git/lesson25_pipe_fifo/Comm.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __COMM_HPP__
#define __COMM_HPP__



#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <cerrno>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
using namespace std;


#define Mode 0666
#define Path "fifo"


class Fifo
{
public:
    Fifo(const string &path):_path(path)
    {
        umask(0);
        int n=mkfifo(_path.c_str(),Mode);
        if(n==0)
        {
            cout<<"mififo success"<<endl;
        }
        else
        {
            cerr<<"mkfifo failed,errno:"<<errno<<",errstring:"<<strerror(errno)<<endl;
        }
    }
    ~Fifo()
    {
        int n=unlink(_path.c_str());
        if(n==0)
        {
            cout<<"remove fifo file"<<_path<<"success"<<endl;
        }
        else
        {
            cerr<<"remove fifo,errno"<<errno<<"errstring"<<strerror(errno)<<endl;
        }
    }
private:
    string _path;//文件路径+文件名
};



#endif